/**
 * Created by forcht on 2018/5/19.
 */
public class Solution {
    public int maxProfit(int[] prices) {
       if (prices==null||prices.length==0)return 0;
       int max=0;
       int min=prices[0];
       for(int i=1;i<prices.length;i++){
           min=Math.min(min,prices[i]);
           max=Math.max(max,prices[i]-min);
       }
       return max;
    }
    public static void main(String[] args) {
        Solution solution=new Solution();
        int[] a={2,4,1};
        System.out.println(solution.maxProfit(a));
    }
}